﻿@inherits BaseTodoItems
<Row>
    <Column>
        <Card Margin="Margin.Is4.FromTop">
            <CardHeader Padding="Padding.Is1.FromBottom">
                <Heading Size="HeadingSize.Is4">Todo List</Heading>
            </CardHeader>
            <CardBody Padding="Padding.Is0.FromBottom">
                <Fields>
                    <Column ColumnSize="ColumnSize.Is1">
                        <CheckEdit Checked="@Todos.All(x=>x.Completed)" CheckedChanged="@OnCheckAll">All</CheckEdit>
                    </Column>
                    <Column ColumnSize="ColumnSize.Is11">
                        <Addons>
                            <Addon AddonType="AddonType.Body">
                                <Validations @ref="validations" @ref:suppressField Mode="ValidationMode.Manual">
                                    <Validation Validator="@ValidationRule.IsNotEmpty">
                                        <TextEdit @bind-Text="@description" Placeholder="What needs to be done?"></TextEdit>
                                    </Validation>
                                </Validations>
                            </Addon>
                            <Addon AddonType="AddonType.End">
                                <SimpleButton Color="Color.Primary" Clicked="@OnAddTodo">
                                    <Icon Name="IconName.New" />Add
                                </SimpleButton>
                            </Addon>
                        </Addons>
                    </Column>
                </Fields>
            </CardBody>
            <CardBody Padding="Padding.Is0.OnY">
                <ListGroup IsFlush="true">
                    @foreach ( var todo in Todos )
                    {
                        <TodoItem Todo="@todo" StatusChanged="@OnTodoStatusChanged" />
                    }
                </ListGroup>
            </CardBody>
            <CardFooter Padding="Padding.Is3.FromBottom">
                <Field IsHorizontal="true">
                    <FieldBody ColumnSize="ColumnSize.Is10">
                        <Buttons Role="ButtonsRole.Addons">
                            <SimpleButton Color="Color.Info" Clicked="@(() => SetFilter( Filter.All ))" IsActive="@(filter == Filter.All)">All</SimpleButton>
                            <SimpleButton Color="Color.Info" Clicked="@(() => SetFilter( Filter.Active ))" IsActive="@(filter == Filter.Active)">Active</SimpleButton>
                            <SimpleButton Color="Color.Info" Clicked="@(() => SetFilter( Filter.Completed ))" IsActive="@(filter == Filter.Completed)">Completed</SimpleButton>
                        </Buttons>
                    </FieldBody>
                    <FieldBody ColumnSize="ColumnSize.Is2">
                        <SimpleButton Color="Color.Warning" Float="Float.Right" Clicked="@OnClearCompleted" Visibility="@(todos.Any(x=>x.Completed) ? Visibility.Always : Visibility.Never)">Clear Completed</SimpleButton>
                    </FieldBody>
                </Field>
            </CardFooter>
        </Card>
    </Column>
</Row>